<template lang="pug">
.saleedit
  el-dialog(title="调整商品" :visible="value" width='425px' @close="comfirm")
    el-form(:model="form")
      el-form-item(label="活动名称" label-width="100px")
        el-input(v-model="form.name" :disabled="true")
      el-form-item(label="上架时间" label-width="100px")
        el-date-picker(v-model="form.sale_time" type="datetime" placeholder="选择日期时间")
      el-form-item(label="价格" label-width="100px")
        el-input(v-model="form.price")
          template(slot="append") 元
      el-form-item(label="库存" label-width="100px")
        el-input(v-model="form.stock")
          template(slot="append") 元
    div(slot="footer" class="dialog-footer")
      el-button(@click="comfirm") 取 消
      el-button(type="primary" @click="onSubmit") 确 定
</template>
<script>
export default {
  props:{
    value:{
      type:Boolean,
      default:false
    },
    row:{
      type:Object,
      default:() => ({})
    }
  },
  data() {
    return {
      form:{
        name:'',
        sale_time:'',
        price:'',
        stock:''
      }
    }
  },
  watch: {
    row(v) {
      this.form = {
        ...v
      }
    }
  },
  methods: {
    comfirm() {
      this.form = {
        name:'',
        sale_time:'',
        price:'',
        stock:''
      }
      this.$emit('input',false)
    },

    onSubmit() {
      this.axios.post('/sale/adjust',{id:this.row.id,price:+this.form.price,stock:+this.form.stock,sale_time:this.form.sale_time}).then(({data}) => {
        console.log(data);
        if(!data.errcode) {
          this.$message({
            message: '修改成功',
            type: 'success'
          });
          this.comfirm()
          this.$emit('edit')
        }
      })
    }
  },
}
</script>
